package com.fromfuture.xuhuidoc.cordova.plugin;

import com.fromfuture.xuhuidoc.cordova.untils.CordovaAppManager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

/**
 * Created by hp on 2017/6/20.
 */

public class MySystemPlugin extends CordovaPlugin {
    private static CallbackContext mCallbackContext;
    private String FINISHACTIVITY = "fishactivity";




    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        mCallbackContext=callbackContext;
//        Toast.makeText(cordova.getActivity(),"1234567",Toast.LENGTH_SHORT).show();

        try{
            if (action.equals(FINISHACTIVITY)){
                cordova.getActivity().finish();
            }
        }catch (Exception e){
            return false;
        }


        return false;
    }

    public void callJSs(String message) {

        CordovaAppManager.myConsultRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (CordovaAppManager.mycordovaWebView==null){

                }else if (CordovaAppManager.mycordovaWebView!=null){
                    CordovaAppManager.mycordovaWebView.loadUrl("javascript:"+ "abc(\'"+ "取消按钮回复: java自己调用js方法" +"\')");
                }
            }
        });

    }

    public void callJZ(){
        CordovaAppManager.myConsultRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (CordovaAppManager.mycordovaWebView==null){

                }else if (CordovaAppManager.mycordovaWebView!=null){
                    CordovaAppManager.mycordovaWebView.loadUrl("javascript:"+ "myinit(\'" + "取消按钮回复: java自己调用js方法" + "\')");
//                    CordovaAppManager.mycordovaWebView.loadUrl("javascript:"+ "hsj(\'" + "取消按钮回复: java自己调用js方法" + "\')");
                }
            }
        });
    }

}
